<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>Inheritance.html</title>

		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="this is my page">
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">

		<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
		<script type="text/javascript">
////实现继承的方式

//对象的继承
function Parent(name) {

	this.name = name;
	this.sayName = function() {
		alert(this.name);
	}
}

///一,二，三，的缺点：
//方法的声明必须写在构造方法内，
//否则无法生效

//一.用对象冒充的方式实现继承
function Child(name, password) {
	this.method = Parent;
	this.method(name);
	delete this.method;

	this.password = password;
	this.sayPassword = function() {
		alert(this.password);
	}
}

var o1 = new Parent("kevin");
var o2 = new Child("annie", 123);

/*o1.sayName();
 o2.sayName();*/

/*	o1.sayName();
 o2.sayName();
 o2.sayPassword();*/

//二.用call方法的方式实现继承
function Parent(name) {

	this.name = name;
	this.sayName = function() {
		alert(this.name);
	}
}

function Child(name, password) {
	this.password = password;
	this.sayPassword = function() {
		alert(this.password);
	}
	Parent.call(this, name)
}

var o1 = new Parent("kevin");
var o2 = new Child("annie", 123);

/*o1.sayName();
 o2.sayName();*/
//二.用call方法的方式实现继承
function Parent(name) {

	this.name = name;
	this.sayName = function() {
		alert(this.name);
	}
}

function Child(name, password) {
	this.password = password;
	this.sayPassword = function() {
		alert(this.password);
	}
	Parent.apply(this, new Array(name));
}

var o1 = new Parent("kevin");
var o2 = new Child("annie", 123);

//o1.sayName();
//o2.sayName();

//四.原型链的方式实现继承
//缺点：子类对像共用父类中的属性。
function SuperType() {
	this.property = true;
}

SuperType.prototype.getSupperValue = function() {
	return this.property;
}

function SubType() {
	this.subproperty = false;
}

SubType.prototype = new SuperType();
SubType.prototype.getSubValue = function() {
	return this.subproperty;
};

var subType = new SubType();

//五.混合继承方式
function SuperType(name) {
	this.name = name;
}

SuperType.prototype.getSupperValue = function() {
	return this.name;
}

function SubType(name) {
	this.subproperty = false;
	SuperType.call(this, name);
}

SubType.prototype = new SuperType();

var o1 = new SubType("kevin");
alert(o1.getSupperValue());

//alert(subType.getSubValue());
//alert(subType.getSupperValue());
</script>
	</head>

	<body>
		<br>
	</body>
</html>
